× Home (CS 211) Notes Projects Waxman's Website

Purpose

The goal of this project is to print a chess board graphic of the solutions to 8 queens problem. This project will be utilize typedef.

Box

box typedef
box is now a datatype that refers to a 2D array, with 5 rows and 7 columns of characters.
bb and wb are both of the type box; they are both 2D arrays of characters with 5 rows and 7 columns.
Board is a 2D array with 8 rows and 8 columns that contains pointers to variables of box type. They store the address of box variables.

bb and wb


bb stands for black box so each element of the array contains char(219), which is the ascii code of a black box.
wb stands of white box so each element contains an empty space.
Remember that both wb and bb are of the type box, which is a 2D array of CHARACTERS. So in bb we are storing a char and wb the empty space is in single quotes and not double quotes.

Board

Notice how we only create one bb and one wb, but a chessboard has more than 2 boxes. This is because board is a 2D array of pointers to the box type. Each element of board is a a pointer to a box, and therefore stores the memory address of the box. We will uses only the one bb and wb to populate the entire array of board. Where a white box is, the address of wb will be stored and where a black box is, the address of bb is stored.

Adding in the Queens

Set up the current solution on the chessboard by placing pointers to bq and wq in the appropriate square. bq is a queen on a black square and wq is a queen on a white square.

Printing the board


*board[i][j] retrieves box pointer from board and then deference it. Doing so give access to the box that is being pointed to.


Resources
Template
Sample Output
This is to be submitted on blackboard as a .cpp file. File name follows the following format: lastName_firstName.cpp